<?php
	require '../../include/library.inc.php';
	require '../../include/admin_login.inc.php';
	
	if($_POST['data'] && $_POST['type']) {
  	
		$sql = "UPDATE `setings` SET `values`  = '".$_POST['data']."' WHERE `type` = '".$_POST['type']."'";
		query($sql);
		
		 $arr =  json_c_decode($_POST['data']);
		 
		 function parents($ar,$parent)
		 {
			 foreach ($ar as $key => $value) {
				 
				 $sql = "UPDATE pages SET
				  parent_id = '".$parent."'
			    WHERE
				  page_id = '".$value['id']."'
				";
				query($sql);
				
				if($value['children']) parents($value['children'],$value['id']);
				 
			 }
		 }
		 
		 function parents_info($ar,$parent)
		 {
			 foreach ($ar as $key => $value) {
				 
				 $sql = "UPDATE infos SET
				  parent_id = '".$parent."',
				  order_number = '".$key."'
			    WHERE
				  info_id = '".$value['id']."'
				";
				query($sql);
				
				if($value['children']) parents_info($value['children'],$value['id']);
				 
			 }
		 }
		 if($_POST['data'] && $_POST['type'] == 'tabs') parents($arr,0);
		 if($_POST['data'] && $_POST['type'] == 'info') parents_info($arr,0);
		
		
		echo 'Save ...';
	
	}
  
	
?>